﻿Imports VSModel
Imports Cls_Common
Partial Class Control_WhatCookToDay_FeaturedDishes
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            LoadFeaturedDishes()
        End If
    End Sub
#Region "Sub and function"
    'Load cac mon an duoc xem nhieu nhat
    Sub LoadFeaturedDishes()
        Using ssmdata As New VSEntities
            Dim curDateOfWeek As Integer = Now.DayOfWeek
            Dim bDateOfCurWeek As DateTime = Now.Date.AddDays(-(curDateOfWeek - 1))
            Dim eDateOfCurWeek As DateTime = bDateOfCurWeek.AddDays(6)

            'Add DomainName DUC 09-09-2014
            Dim sList = (From f In ssmdata.formulae Where f.Domain = DomainName And f.StatusId = 3 _
                         And f.PublishedDate >= bDateOfCurWeek _
                         And f.PublishedDate <= eDateOfCurWeek _
                         And (f.eEffectiveDate >= Now Or f.eEffectiveDate Is Nothing) _
                         Order By f.Viewed Descending Select New With {f.QueryString, f.Id, f.Viewed, f.Created, f.PublishedDate, .QueryStringFT = f.FormulaType.QueryString, f.Title}).Skip(0).Take(5).ToList()
            With rptList
                .DataSource = sList
                .DataBind()
            End With
        End Using
    End Sub

    Protected Sub rptList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptList.ItemDataBound
        Dim p = CType(e.Item.DataItem, Object)
        Dim lblView As Label = CType(e.Item.FindControl("lblView"), Label)
        lblView.Text = Convert.ToDateTime(p.PublishedDate).ToString("dd/MM/yyyy")
        
        Dim hplName As HyperLink = CType(e.Item.FindControl("hplName"), HyperLink)
        hplName.NavigateUrl = "~/" & Page.RouteData.Values("MenuId") & "-" & strRewriteWhatCookToday & "/" & p.QueryStringFT.ToString & "/" & p.QueryString.ToString & "-" & p.Id.ToString & ".html"
        hplName.Text = p.Title.ToString()
    End Sub
#End Region
End Class
